package com.tuanzi.loan.business.service.galaxycard.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tuanzi.loan.business.entity.CurrentUser;
import com.tuanzi.loan.business.repository.galaxycard.GalaxyCardOrderStatRepository;
import com.tuanzi.loan.business.service.galaxycard.GalaxyCardOrderStatService;
import com.tuanzi.loan.business.service.galaxycard.GalaxyCardPromoteUserRelateChannelService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.galaxycard.GalaxyCardOrderStatRequest;
import com.tuanzi.loan.vo.response.galaxycard.GalaxyCardOrderStatResponse;

@Debug
@Service
@Transactional
@Retryable(value = { RetryException.class })
public class GalaxyCardOrderStatServiceImpl implements GalaxyCardOrderStatService{
	
	@Autowired
	private GalaxyCardOrderStatRepository galaxyCardOrderStatRepository;
	
	@Autowired
	private GalaxyCardPromoteUserRelateChannelService galaxyCardPromoteUserRelateChannelService;
	
	
	@Override
	public Page<GalaxyCardOrderStatResponse> list(
			PageSearcher<GalaxyCardOrderStatRequest> pageSearcher) {
		
		List<Integer> channelCodeList = galaxyCardPromoteUserRelateChannelService.findChannelCodeListByUserId(CurrentUser.get().getUserId());
		pageSearcher.getSearchCondition().setChannelCodeList(channelCodeList);
		return galaxyCardOrderStatRepository.list(pageSearcher.getSearchCondition(), pageSearcher.getPageable());
	}

}
